﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="code1.aspx.cs" Inherits="code1" %>
    /// <summary>
    /// Author:喻旻
    /// Create date: <%=DateTime.Now.Date.ToString("yyyy-MM-dd") %>
    /// Description: <%=TableDesc %>
    /// </summary>
    public class <%=TableName_Emoney%>DAL
    {
        public void Add(<%=TableName_Emoney%> c)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("INSERT INTO [<%=TableName %>] (<%=GetColumns("") %>) VALUES(<%=GetSpsCol() %>)");
            SqlHelperTask.AddTask(DBConn.Msn, sb.ToString());
        }

        public void Update(<%=TableName_Emoney%> c)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("UPDATE [<%=TableName%>]");
            <%=UpdateColums() %>
            sb.AppendLine(" WHERE <%=UpdateWhere() %>");
            SqlHelperTask.AddTask(DBConn.Msn, sb.ToString());
        }

        public bool IsExists(<%=GetKeys() %>)
        {
            string sql = "select count(*) from <%=TableName%> where <%=IsExistsWhere() %>";
            Tools tool=new Tools();
            <%=IsExistsColumn()%>
            object obj = SqlHelper.ExecuteScalar(DBConn.Msn, System.Data.CommandType.Text, sql, tool.GetSqlParameters());
            int count = Convert.ToInt32(obj);
            if (count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public List<<%=TableName_Emoney%>> GetLstFromEmoney(DateTime? time)
        {
            if (time == null)
            {
                string sql = "select " + SqlHelper.PropertiesToString(typeof(<%=TableName_Emoney%>), null, null) + " from <%=TableName_Emoney %> order by RecTime";
                return SqlHelper.GetDataByColumnsLst<<%=TableName_Emoney%>>(DBConn.Emoney, sql, null);
            }
            else
            {
                string sql = "select " + SqlHelper.PropertiesToString(typeof(<%=TableName_Emoney%>), null, null) + " from <%=TableName_Emoney %> where RecTime>=@time or ModTime>=@time order by RecTime";
                Tools tool = new Tools();
                tool.AddSqlParameter("time", System.Data.SqlDbType.DateTime, time);
                return SqlHelper.GetDataByColumnsLst<<%=TableName_Emoney%>>(DBConn.Emoney, sql, tool.GetSqlParameters());
            }
        }

        public DateTime? GetMaxTime()
        {
            string sql2 = "select MAX(RecTime) from <%=TableName%>";
            object obj2 = SqlHelper.ExecuteScalar(DBConn.Msn, System.Data.CommandType.Text, sql2, null);
            if (obj2 != DBNull.Value)
            {
                return Convert.ToDateTime(obj2);
            }
            else
            {
                return null;
            }
        }
    }